
<%--
  Created by IntelliJ IDEA.
  User: zhuya
  Date: 2016/1/28
  Time: 16:45
  所有咨询
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>咨询服务</title>
    <link rel="stylesheet" href="<c:url value="/resource/wechat/css/frozen.css"></c:url>">
    <link rel="stylesheet" type="text/css" href="<c:url value="/resource/wechat/css/main.css"></c:url>"/>
    <style type="text/css">
        .sslk_more {
            width: 98%;
            float: left;
            margin-left: 1%;
            height: 35px;
            line-height: 35px;
            color: #fff;
            text-align: center;
            background: rgb(109, 189, 99);
            border-radius: 3px;
            clear: both;
            margin-top: 15px;
            margin-bottom: 15px;
            font-family: "微软雅黑", "黑体", "宋体";
            font-size: 1.0rem;
        }
        .sslk_more a {
            color: #fff;
            text-decoration: none;
        }
        #pr_list_foot {
            margin: 0;
            padding: 0;
            height: 3rem;
            line-height: 3rem;
            width: 100%;
            border: none;
            text-align: center;
            -webkit-font-smoothing: antialiased;
            font-size: 0.95rem;
            color: #aba0a0;
        }
        #pr_list_foot a {
            display: block;
            height: 3rem;
            width: 7.5rem;
            margin: 0 auto;
            padding: 0;
            text-align: center;
            font-weight: normal;
            text-decoration: none;
            color: #aba0a0;
        }
    </style>
</head>
<body ontouchstart class="bg_fff">



<section class="ui-container">
    <div class="mart20"></div>
    <div class="search_wrap">
        <div class="search_main">
            <div class="search_main_rt">
                <input type="button" onclick="searchKeys();"/>
            </div>
            <div class="search_main_lf">
                <input type="text" placeholder="关键字搜索" id="keyword"/>
            </div>
        </div>
    </div>
    <div class="ui-btn-wrap">
        <button class="ui-btn-lg ui-btn-primary" onclick="ask()">
            我要提问
        </button>
    </div>
    <div style="clear: both;"></div>
    <div id="all_zx_main">
    </div>
    <div id="pr_list_foot"><a class="foot_icon" href="javascript:void(0)" id="moreButton">加载更多</a></div>
</section>
<script src="<c:url value='/resource/js/jquery-2.0.min.js'/>"></script>
<script type="text/javascript">
    var page_index = 1;
    $(function () {
        search();
        $("#moreButton").click(function () {
            this.innerHTML = "加载中";
            page_index++;
            search();
        });
    });
    //我要提问跳转
    function ask() {
        <%--if(${member!=null and member.guid!=null and member.guid!=''}){--%>
            location.href = "<c:url value='/weixin/bszx/askQuestion?pt=${pt}'/>";
        <%--}else{--%>
            <%--location.href = "<c:url value='/weixin/wx_member/login'/>";--%>
        <%--}--%>
    }

    function searchKeys() {
        page_index = 1;
        $("#all_zx_main").empty();
        search();
    }

    function showAns(t,obj, id) {
        if($(t).hasClass("hasClick")){
            return;
        }else{
            $(t).addClass("hasClick");
        }

        if(null==obj){
        content = '<div class="wdzx_main" onclick="doClear(this)">'
                + '<div class="wdzx_main_ren ren2"><img src="<c:url value="/resource/wechat/images/wdzx_ren.png"></c:url>"/></div>'
                + '<div class="wdzx_main_gongg left">'
                + '<div class="img1"><img src="<c:url value="/resource/wechat/images/jiantou1.png"></c:url>"/></div>'
                + '<div class="main">'
                + '<div class="main_neir">'
                + '<p>当前咨询，没有回答。</p></div> </div> </div> </div>';
            $(t).after(content);
        }
        else{
        <%--$.ajax({--%>
            <%--url: "<c:url value='/api/matters/consult/answer/"+id+"'></c:url>",--%>
            <%--success: function (resp) {--%>
                <%--console.info(JSON.stringify(resp));--%>
                <%--if (resp.succ) {--%>

                    content = '<div class="wdzx_main" onclick="doClear(this)">'
                            + '<div class="wdzx_main_ren ren2"><img src="<c:url value="/resource/wechat/images/wdzx_ren.png"></c:url>"/></div>'
                            + '<div class="wdzx_main_gongg left">'
                            + '<div class="img1"><img src="<c:url value="/resource/wechat/images/jiantou1.png"></c:url>"/></div>'
                            + '<div class="main">'
                            + '<div class="main_neir">'
                            + '<p>'+id+'</p>'
                            + '<p class="pa">'+obj+'</p> </div> </div> </div> </div>';
                    $(t).after(content);
        }
//                }
//            },
//            error: function (resp) {
//            }
//        });
    }

    function doClear(obj){
        var pre = $(obj).prev();
        $(pre).removeClass("hasClick");
        $(obj).remove();
    }
    function search() {
        <%--var url = "<c:url value='/api/matters/page/consult'/>" + "?keyword=" + $("#keyword").val() + "&page_size=10&page_index=" + page_index;--%>
        var url = "<c:url value='/api/matters/page/consult'/>";
        var keyword = $("#keyword").val();
        $.ajax(url, {
            type: "post",
            data: '{"keywords":"'+ $("#keyword").val() + '","numPerPage":"10","pageNum":' + page_index +'}',
            contentType:"application/json",
            success: function (msg) {
                if (msg["succ"]) {
                    var totalPages = parseInt(msg["data"].totalPages);
                    if (totalPages > 0) {
                        addTolist(msg["data"].list);
                        if (totalPages > page_index) {
                            $("#pr_list_foot").css("visibility", "visible");
                            $("#moreButton").html("加载更多");
                        }
                        else {
                            $("#pr_list_foot").css("visibility", "hidden");
                        }
                    }
                } else {
                    $("#pr_list_foot").css("visibility", "hidden");
                }
            },
            error: function (resp) {
              //  console.info(JSON.stringify(resp));
            }
        });
    }

    function addTolist(result) {
        var content = "";
        for (var i = 0; i < result.length; i++) {
            content += '<div class="wdzx_main" onclick="showAns(this,\'' + result[i].consultAnswer.answerTimeB+ '\',\'' + result[i].consultAnswer.conetent+ '\');">'
                    + '<div class="wdzx_main_ren ren1"><img src="<c:url value="/resource/wechat/images/wdzx_ren.png"></c:url>"/></div>'
                    + '<div class="wdzx_main_gongg right">'
                    + '<div><img src="<c:url value="/resource/wechat/images/jiantou.png"></c:url>"/></div>'
                    + '<div class="main">'
                    + '<div class="main_neir">'
                    + '<p>' + result[i].subject + '</p>'
                    + '<p class="pa">' + result[i].cosTime + '</p></div></div></div></div></div>';
        }
        $("#all_zx_main").append(content);
    }

    function getConetnt(content) {
        if (content) {
            return content;
        } else {
            return '';
        }
    }

    /**
     *
     * @param type  1:提问  2：咨询
     */
    function getGuid(type) {
        <%--var user = "${member}";--%>
        var user = "====================";
        var gowhere = "";
        if (user == "" || user == null || user == undefined || user == "null") {
            if ("1" == type) {
                gowhere = "/weixin/bszx/askQuestion";
            }
            if ("2" == type) {
                gowhere = "/weixin/bszx/myconsulting";
            }
            window.location.href = "<c:url value='/weixin/wx_member/login'/>" + "?gowhere=" + gowhere;
        } else {
            if ("1" == type) {
                window.location.href = "<c:url value='/weixin/bszx/askQuestion'/>";
            }
            if ("2" == type) {
                window.location.href = "<c:url value='/weixin/bszx/myconsulting'/>";
            }
        }
    }
</script>
</body>
</html>